<!DOCTYPE html>
<html>
    {include file='public/header'}
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="javascript:void(0)">首页</a>
                <a href="javascript:void(0)">抖音私域</a>
                <a>
                    <cite>粉丝群</cite>
                </a>
            </span>
            <a class="layui-btn layui-btn-small" id="reload" title="刷新">
                <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
            </a>
        </div>
        <div class="layui-row">
            <form class="layui-form searchForm">
                <div style="display: flex;margin-top: 20px;">
                    <div class="layui-inline">
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>openid:
                            </label>
                            <div class="layui-input-block">
                                <select class="project-select" style="width: 150px;" id="open_id" name="open_id" lay-filter="open_id">
                                    <option value="">请选择openId</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchFinanceList">搜索</button>
                    <button type="reset" id="resetFinanceList" class="layui-btn layui-btn-primary">重置</button>
                </div>

            </form>
            <div class="x-body">
                <table id="fansGroupList" lay-filter="fansGroupList"></table>
            </div>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="add">新增粉丝群</button>
                </div>
            </script>
            <script>
                let openid = ''
                function getOpenidList() {
                    Ajax(`/admin/openDouyin/getOpenId`, {}, 'get').then(res => {
                        if (res.code === 200) {
                            $.each(res.data, function (index, item) {
                                $('#open_id').append(new Option(item.short_id, item.open_id));
                            });
                            layui.form.render("select");
                        }
                    });
                }
                getOpenidList()
                layui.use([
                    'layer', 'element', 'form'
                ], function () {
                    form = layui.form;
                    var table = layui.table;
                    form.on('select(open_id)', function (data) {
                        openid = data.value; // 获取选中的值
                        var text = data.elem[data.elem.selectedIndex].text;
                        // 获取选中的文本

                        // 搜索
                    });
                    // 搜索
                    form.on('submit(searchFinanceList)', function (data) {
                        console.log("openid----", openid)
                        params.where = {
                            ... data.field
                        }
                        console.log('搜索参数', params)
                        tableList(params)
                        return false
                    });
                    // 重置
                    $('#resetFinanceList').on('click', function () {
                        params.where = {
                            openid:''
                        }
                        tableList(params)
                    });
                    table.on('toolbar(fansGroupList)', function (obj) {
                        var event = obj.event;
                        if (event === 'add') {
                            x_admin_show('新增粉丝群', `./info.html`, 650, 600);
                        }
                    });
                });
                let params = {
                    elem: '#fansGroupList',
                    toolbar: '#toolbarDemo',
                    url: `/admin/openDouyin/getGroupFans?open_id=${
                        openid
                    }`,
                    id: 'fansGroupList',
                    cols: [
                        [
                            { // 表头
                                field: 'id',
                                title: '群组id',
                                width: 120
                            },
                            {
                                field: 'group_name',
                                title: '群名称'
                            },
                            {
                                field: 'group_type',
                                title: '粉丝群',
                                templet: function (d) {
                                    return d.group_type == 2 ? '主播粉丝群' : '万粉群'
                                }
                            }, {
                                field: 'description',
                                title: '群简介'
                            }, {
                                field: 'open_audit_switch',
                                title: '进群审批',
                                templet: function (d) {
                                    return d.open_audit_switch == 1 ? '开启' : '不开启'
                                }
                            }, {
                                field: 'show_at_profile',
                                title: '个人简介',
                                templet: function (d) {
                                    return d.show_at_profile == 1 ? '展示' : '不展示'
                                }
                            }, {
                                field: 'live_auto_sync',
                                title: '直播同步',
                                templet: function (d) {
                                    return d.live_auto_sync == 1 ? '同步' : '不同步'
                                }
                            }, {
                                field: 'item_auto_sync',
                                title: '作品同步',
                                templet: function (d) {
                                    return d.item_auto_sync == 1 ? '同步' : '不同步'
                                }
                            }, {
                                field: 'exist_num',
                                title: '群现有人数'
                            }
                        ]
                    ]
                }
                tableList(params);
            </script>
        </body>
    </body>
</html>
